package com.lzy.mall.coupon.service;

import java.util.List;

import com.lzy.mall.coupon.entity.SmsMemberPrice;
import com.lzy.mall.coupon.dao.SmsMemberPriceDao;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * 商品会员价格(SmsMemberPrice)表服务
 *
 * @author lzy
 * create on 2021-10-14 11:06:24
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class SmsMemberPriceService {
    private final SmsMemberPriceDao smsMemberPriceDao;

    public SmsMemberPrice queryById(Long id) {
        return smsMemberPriceDao.single(id);
    }

    public List<SmsMemberPrice> queryAll() {
        return smsMemberPriceDao.all();
    }

    @Transactional(rollbackFor = Exception.class)
    public void insert(SmsMemberPrice smsMemberPrice) {
        smsMemberPriceDao.insertTemplate(smsMemberPrice, true);
    }

    /**
     * 根据主键更新记录
     *
     * @param smsMemberPrice 待更新的记录.包含主键在内，如果其他列的值为空则不更新
     * @return 成功返回true，失败返回false
     */
    public boolean updateById(SmsMemberPrice smsMemberPrice) {
        return smsMemberPriceDao.updateTemplateById(smsMemberPrice) > 0;
    }

    /**
     * 根据主键删除记录
     *
     * @param id 主键
     * @return 成功返回true，反之返回false
     */
    public void deleteById(List<Long> id) {
        smsMemberPriceDao.createLambdaQuery()
                .andIn(SmsMemberPrice::getId, id)
                .delete();
    }

    /**
     * 分页查询
     *
     * @param pageQuery 封装分页条件的分页对象
     * @return pageQuery 作为一个引用，将查询结果封装进去
     */
    public PageQuery<SmsMemberPrice> queryByPage(PageQuery<SmsMemberPrice> pageQuery) {
        smsMemberPriceDao.queryByPage(pageQuery);
        return pageQuery;
    }
}
